package kr.hkit.powerjava.chapter22.work2;

import java.util.ArrayList;
import java.util.Comparator;

import kr.hkit.powerjava.chapter22.work2.doa.DepartmentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.doa.StudentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.vc.Department;
import kr.hkit.powerjava.chapter22.work2.vc.Student;

public class TestMain {
	public static void main(String[] args) {

		ArrayList<Student> stdList = new ArrayList<>();
		StudentManagerImpl sm = new StudentManagerImpl(stdList);

		Student std1 = new Student(1, "김태희", 90, 90, 90);
		sm.addItem(std1);
		Student std2 = new Student(2, "제시카", 89, 79, 77);
		sm.addItem(std2);
		sm.addItem(new Student(3, "김주하", 89, 75, 87));
		sm.addItem(new Student(4, "한가인", 85, 79, 90));

		sm.prnItems(); // 검색 
		Student searchItem = new Student(1,"김태희");
		String result = sm.searchItem(searchItem) ? "존재" : "없음";
		System.out.println(searchItem.getStdNum() + ":" + ""
				+ searchItem.getStdName() + " = " + result);

		// 수정
		Student updateItem = new Student(1,"김태희",91,93,94);
		sm.updateItem(updateItem);
		sm.prnItems();

		// 출력
		sm.prnItems(); System.out.println("총점 순 정렬");
		Comparator<Student> totalCom = new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				return (int) (o2.getTotal() - o1.getTotal());
			}
		};
		sm.prnItems(totalCom);

		System.out.println("이름 순 정렬");
		Comparator<Student> com = new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				return o1.getStdName().hashCode() - o2.getStdName().hashCode();
			}

		};
		sm.prnItems(com);

		System.out.println("국어 점수 정렬(내림차순)");
		sm.prnItems(new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				return o2.getKor() - o1.getKor();
			}
			
		});

		for(Student std : stdList) {
			System.out.println(std);
		}
		
		System.out.println("반복자===========================");
		Student std = null;
		
		
		
	/*	ArrayList<Department> deptList = new ArrayList<>();
		DepartmentManagerImpl dm = new DepartmentManagerImpl(deptList);

		Department dept1 = new Department(1, "컴공", 4);
		dm.addItem(dept1);
		Department dept2 = new Department(3, "기공", 2);
		dm.addItem(dept2);
		Department dept3 = new Department(2, "전자", 5);
		dm.addItem(dept3);

		dm.prnItems();
		// 검색
		Department searchItem = new Department(1, "컴공");
		String result = dm.searchItem(searchItem) ? "존재" : "없음";
		System.out.println(searchItem.getDeptNo() + ":" + ""
				+ searchItem.getDeptName() + " = " + result);

		dm.updateItem(new Department(1, "컴공", 7));
		dm.prnItems();

		// 출력
		dm.prnItems();
		System.out.println("위치 순 정렬");
		Comparator<Department> floorCom = new Comparator<Department>() {

			@Override
			public int compare(Department o1, Department o2) {
				return (int) (o2.getFloor() - o1.getFloor());
			}
		};
		dm.prnItems(floorCom);

		System.out.println("학과번호 순 정렬");
		Comparator<Department> deptCom = new Comparator<Department>() {

			@Override
			public int compare(Department o1, Department o2) {
				return (int) (o1.getDeptNo() - o2.getDeptNo());
			}
		};
		dm.prnItems(deptCom);
*/
	}
}
